package cn.gdchent.nativehotfix.tinker.manager

import android.content.Context
import com.tencent.tinker.lib.tinker.Tinker
import com.tencent.tinker.lib.tinker.TinkerInstaller
import com.tencent.tinker.loader.app.ApplicationLike

/**
 * 对Tinker的api进行一层封装
 */
class TinkerManager {

    companion object {
        var isInstalled=false
        var mApplicationLike:ApplicationLike?=null;

        /**
         * 完成tinker的初始化
         */
        fun installTinker(applicationLike: ApplicationLike){
            mApplicationLike=applicationLike
            if(Tinker.isTinkerInstalled()){
                return
            }
            TinkerInstaller.install(applicationLike)
            isInstalled=true
        }
        //加载patch文件
        fun loadPatch(path:String){
            if(Tinker.isTinkerInstalled()){
                TinkerInstaller.onReceiveUpgradePatch(getApplicationContext(),path)
            }
        }

        //获取上下文
        fun getApplicationContext(): Context?{
            return mApplicationLike?.application?.applicationContext
        }
    }
}